Telegram Group & Telegram Channel
🔧 Как настроить Service Worker для офлайн-режима

Service Worker — это JS-скрипт, работающий в фоне. Он позволяет кэшировать ресурсы и обслуживать запросы без подключения к сети.

Почему важно:

🎱 Доступ к сайту без интернета

🎱 Быстрая загрузка повторно посещаемых страниц

🎱 Гибкий контроль над кэшированием

Как внедрить:

1. Регистрируем Service Worker:

if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then(() => console.log('SW зарегистрирован'))
.catch(err => console.error('SW ошибка:', err));
}


2. Создаем sw.js:

const CACHE_NAME = 'app-cache-v1';
const urlsToCache = ['/', '/index.html', '/styles.css'];

self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME).then(cache => cache.addAll(urlsToCache))
);
});


3. Обслуживаем запросы:

self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => response || fetch(event.request))
);
});


4. Обновляем кэш при необходимости:

self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(keys =>
Promise.all(keys.filter(key => key !== CACHE_NAME).map(key => caches.delete(key)))
)
);
});


💡 С помощью Service Worker можно создавать PWA, ускорять загрузку и обеспечить стабильную работу в нестабильных сетях.

🐸 Библиотека фронтендера

#буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/frontendproglib/6244
Create:
Last Update:

🔧 Как настроить Service Worker для офлайн-режима

Service Worker — это JS-скрипт, работающий в фоне. Он позволяет кэшировать ресурсы и обслуживать запросы без подключения к сети.

Почему важно:

🎱 Доступ к сайту без интернета

🎱 Быстрая загрузка повторно посещаемых страниц

🎱 Гибкий контроль над кэшированием

Как внедрить:

1. Регистрируем Service Worker:

if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then(() => console.log('SW зарегистрирован'))
.catch(err => console.error('SW ошибка:', err));
}


2. Создаем sw.js:

const CACHE_NAME = 'app-cache-v1';
const urlsToCache = ['/', '/index.html', '/styles.css'];

self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME).then(cache => cache.addAll(urlsToCache))
);
});


3. Обслуживаем запросы:

self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => response || fetch(event.request))
);
});


4. Обновляем кэш при необходимости:

self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(keys =>
Promise.all(keys.filter(key => key !== CACHE_NAME).map(key => caches.delete(key)))
)
);
});


💡 С помощью Service Worker можно создавать PWA, ускорять загрузку и обеспечить стабильную работу в нестабильных сетях.

🐸 Библиотека фронтендера

#буст

BY Библиотека фронтендера | Frontend, JS, JavaScript, React.js, Angular.js, Vue.js




Share with your friend now:
tg-me.com/frontendproglib/6244

View MORE
Open in Telegram


Библиотека фронтендера | Frontend JS JavaScript React js Angular js Vue js Telegram | DID YOU KNOW?

Date: |

Telegram Auto-Delete Messages in Any Chat

Some messages aren’t supposed to last forever. There are some Telegram groups and conversations where it’s best if messages are automatically deleted in a day or a week. Here’s how to auto-delete messages in any Telegram chat. You can enable the auto-delete feature on a per-chat basis. It works for both one-on-one conversations and group chats. Previously, you needed to use the Secret Chat feature to automatically delete messages after a set time. At the time of writing, you can choose to automatically delete messages after a day or a week. Telegram starts the timer once they are sent, not after they are read. This won’t affect the messages that were sent before enabling the feature.

Find Channels On Telegram?

Telegram is an aspiring new messaging app that’s taking the world by storm. The app is free, fast, and claims to be one of the safest messengers around. It allows people to connect easily, without any boundaries.You can use channels on Telegram, which are similar to Facebook pages. If you’re wondering how to find channels on Telegram, you’re in the right place. Keep reading and you’ll find out how. Also, you’ll learn more about channels, creating channels yourself, and the difference between private and public Telegram channels.

Библиотека фронтендера | Frontend JS JavaScript React js Angular js Vue js from jp


Telegram Библиотека фронтендера | Frontend, JS, JavaScript, React.js, Angular.js, Vue.js
FROM USA